#ifndef __KEY_CODE_H__
#define __KEY_CODE_H__

#include "kb_net.h"
#include "kb_def.h"
#include "group-list.h"

#if 0
#define DEBUG
#endif


#define TRACE_LEVEL	4
#define LEVEL_1		1
#define LEVEL_2		2
#define LEVEL_3		3
#define LEVEL_4		4
#define LEVEL_5		5
#define LEVEL_6		6
#define LEVEL_7		7
#define LEVEL_8		8

#define keycode_trace(level, msg...) do { \
		if((level) >= TRACE_LEVEL) { \
			printf("\n\t[%s : %s : %d] ", __FILE__,__FUNCTION__, __LINE__); \
			printf(msg); \
			printf("\n"); \
		} \
	}while(0)


/* 
 * file name 
 */
#define MON_FILE	"mon.cfg"
#define CAM_FILE	"cam.cfg"
#define GROUP_FILE	"group.cfg"

/* 
 * monitor and camera of count 
 */
#define MONITOR_COUNT	100
#define CAMERA_COUNT	1000

/*
 * search type 
 */
#define MONITOR		0xFFFF
#define CAMERA		0xEEEE

typedef unsigned int TYPE;


/*
 * number
 */
#define RUN_NUM_ONE	1
#define MONITOR_ONE 1

#define RUN_NUM_TWO	2
#define MONITOR_TWO 2

#define RUN_NUM_THR	3
#define MONITOR_THR 3

#define RUN_NUM_FOR	4
#define MONITOR_FOR 4

#define RUN_NUM_FIV	5
#define MONITOR_FIV 5


/*
 * group.cfg of operate
 */
typedef struct grouplist
{
	struct list_head list;
	CameraGroup	group;
}grouplist;

/*
 * global struct of keycode handle
 */
struct operate_handle
{
	int monitor_num;
	int camera_num;
	int run_val, hold_val;
	int shot_value ;		// 调用预置位, 设置预置位
	int speed;
	enPtzAction action;
};

typedef enum 
{
	KEYCODE_THREAD_IDLE,
	KEYCODE_THREAD_START,
	KEYCODE_THREAD_STOP,
}keycode_thread_state;

typedef struct _keycode_thread keycode_thread;

struct _keycode_thread
{
	int status;
};


/*
 * 打开文件
 */
FILE* open_file(char * file_name);

/*
 * 处理收到的键盘数据
 */
int ProcessKey(unsigned char * pKeyBuf) ; 

/*
 * 搜索设备ID,返回相应结构.
 *	num : 设备ID
 *  type : MONITOR || CAMERA
 */
TDeviceInfo *search(unsigned int num, TYPE type);

/*
 * print result
 */
void print_result(grouplist *posnode);

/*
 * 搜索单个轮巡组号
 *
 * s_head: 表头
 * s_newnode : 新节点
 * num : 轮巡组号.
 */
int get_signle_group(grouplist * s_head, grouplist * s_newnode, int num);

/*
 * 停止轮巡
 */
int hold_view();

void print_device_info(TDeviceInfo *pdevice);

static void manage_thread(int run_num);
static void cancel_thread(int hold_num);



#endif	/* __KEY_CODE_H__ */

